<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <title>文章审查页面</title>
    <link rel="stylesheet" href="/layui/plugins/layui/css/layui.css" media="all" />
    <script src="/layui/plugins/layui/layui.js"></script>
    <script src="/main/js/jquery.min.js"></script>
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>

    <input id="url" name="url" type="hidden" th:value="${url}"/>
    <input id="count" name="count" type="hidden" />
    <input id="pageNum" name="pageNum" type="hidden" />
<div style="margin: 15px;">
    <fieldset class="layui-elem-field">
        <legend>人员管理控制</legend>
        <form class="layui-form" action="">
            <div class="layui-form-item">

                <label class="layui-form-label">用户名查询</label>
                <div class="layui-input-inline">
                    <input type="text" name="search" placeholder="输入关键字" autocomplete="off" class="layui-input"/>
                </div>

                <div class="layui-input-inline">
                    <button class="layui-btn" lay-submit="" lay-filter="formDemo">查询</button>
                </div>
            </div>

        </form>
        <table id="userList" class="layui-table" lay-filter="demo">
        </table>
    </fieldset>
</div>

<div id="pageDemo"></div>

<script type="text/html" id="barDemo">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-small" lay-event="edit">修改账号状态</button>
    </div>
</script>
<script>
    var url = '/paper/adminPapersData/1';
    var nurl = document.getElementById("url").value;
    var turl = null;
    if (nurl == ''||nurl == null||nurl==undefined){
        turl = url;
    }else turl = nurl;
    var count = null;
    var currPage = null;
    layui.use(['form','laypage', 'layer', 'table', 'element'], function(){
        var form = layui.form,
          layer = layui.layer;//弹层
          table = layui.table; //表格
          element = layui.element;//元素操作
          laypage = layui.laypage; //分页
        table.render({
            id:'tid',
            elem:'#userList',
            width:1350,
//            page:'true',
            url:turl,
            cols: [[
                {field:'id', title: '文章ID', width:80, sort: true}
                ,{field:'title', title: '文章名称', width:200, sort: true}
                ,{field:'sgement', title: '文章片段', width:200, sort: true}
                ,{field:'author', title: '作者编号', width:144, sort: true}
                ,{field:'create_time', title: '创建时间', width:220, sort: true}
                ,{field:'is_pass', title: '文章状态', width:100}
                ,{toolbar:'#barDemo', title: '操作', width:330}
            ]]
        });

        $.ajax({
            url:turl,
            dataType:"json",   //返回格式为json
            type:"GET" ,
            success:function (data) {
                page(data);
            }
        });
        // 定义field变量内容
        var timePick;
        var search ;

        //监听提交
        form.on('submit(formDemo)', function(data) {

            timePick = data.field.timePick;
            search = data.field.search;
            if(timePick != null){
                url = '/paper/adminPapersData/1/'+timePick+'?title='+search;
            }else{
                url = '/paper/adminPapersData/1'+'?title='+search;
            }
            window.location.href = '/paper/adminPapers?url=' + url;
            return false;
        });

        function page(data) {
            count = data.count;
            currPage = data.pageNum;
            //分页 ajax 可以的到当前的count
            laypage.render({
                elem: 'pageDemo' //分页容器的id
                , limit: 10
                , count: count
                , curr: currPage
                , skin: '#1E9FFF' //自定义选中色值
                , skip: true //开启跳页
                , prev: '上一页 '
                , next: ' 下一页'
                , jump: function (obj, first) {
                    if (!first) {
                        var currentPage = obj.curr;//获取点击的页码

                        if(timePick != null){
                            url = '/paper/adminPapersData/'+currentPage+'/'+timePick+'?title='+search;
                        }else{
                            url = '/paper/adminPapersData/'+currentPage+'?title='+search;
                        }

                        window.location.href = '/paper/adminPapers?url=' + url;
                    }
                }

            });



            //监听工具条
            table.on('tool(demo)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data;//获得当前行数据
                id = data.id,
                layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'edit') {
                    var fix = layer.open({
                        type: 2,
                        area: ['1200px', '650px'],
                        content: '/paper/FixPaperStatues/'+id
                    });
                }else if(layEvent === 'view'){

                }
            });
        }

    });

</script>

</body>
</html>